package top.ranzhang.controller.admin;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.entity.TeachingResources;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.ITeachingResourcesService;

/**
 * 课程资源
 */

@RestController
@RequestMapping("/admin/teaching-resources")
public class TeachingResourcesController {


    @Autowired
    private ITeachingResourcesService teachingResourceService;
    /**
     * 创建教材资源
     *
     * @param teachingResource
     */
    @PostMapping
    public Result create(@RequestBody TeachingResources teachingResource) {
        teachingResourceService.Isave(teachingResource);
        return Result.success();
    }

    /**
     * 获取所有教材资源
     *
     * @return
     */
    @GetMapping
    public Result getAll() {
        return Result.success(teachingResourceService.getAll());
    }

    /**
     * 根据ID获取教材资源
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.success(teachingResourceService.getByIds(id));
    }

    /**
     * 更新教材资源
     *
     * @param id
     * @param teachingResource
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable Integer id, @RequestBody TeachingResources teachingResource) {
        teachingResource.setResourceId(id);
        teachingResourceService.update(teachingResource);
        return Result.success();
    }

    /**
     * 删除教材资源
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        teachingResourceService.delete(id);
        return Result.success();
    }
}
